const apiConfig = {
  // 反代服务器地址
  proxyServer: 'http://farmer233.asuscomm.com:5002',
  // api服务器地址
  // server: 'http://127.0.0.1:5000',
  server: 'http://farmer233.top:5002',

  // token前缀
  token_prefix: 'Bearer ',

  // 普通用户接口
  user: {
    // 普通用户登录
    login (user, passwd) {
      return {
        method: 'post',
        url: '/auth/login',
        data: {
          username: user,
          password: passwd
        }
      }
    },
    // 注册用户接口
    regUser (email, user, passwd, addr) {
      return {
        method: 'post',
        url: '/auth/regUser',
        data: {
          username: user,
          password: passwd,
          email: email,
          address: addr
        }
      }
    },
    // 发送验证码接口
    sendCode (username) {
      return {
        method: 'post',
        url: '/auth/sendForgetCode',
        data: {
          username: username
        }
      }
    },
    // 检查验证码接口
    checkCode (username, code, token) {
      return {
        method: 'post',
        url: '/auth/checkCode',
        data: {
          username: username,
          code: code,
          token: token
        }
      }
    },
    // 重新发送验证码接口
    renewPasswd (newPasswd) {
      return {
        method: 'post',
        url: '/auth/resetPassword',
        data: {
          new_password: newPasswd
        }
      }
    },
    // 登录测试接口
    loginTest () {
      return {
        method: 'get',
        url: '/auth/loginTest'
      }
    }
  },
  // 网盘功能部分
  cloud: {
    // 加载文件列表
    loadFile (path = './') {
      return {
        method: 'post',
        url: '/cloud/getInfo',
        data: {
          path: path
        }
      }
    },
    // 上传文件接口
    uploadFile (fileList, path, progressCallBack) {
      const formData = new FormData()
      formData.append('file', fileList[0])
      formData.append('path', path)
      return {
        method: 'post',
        url: '/cloud/upload',
        headers: {
          'Content-Type': 'multipart/form-data;'
        },
        data: formData,
        // 进度回调函数
        onUploadProgress: progressCallBack
      }
    },
    // 新建文件夹
    newFolder (path, newFolderName) {
      return {
        method: 'post',
        url: '/cloud/make_folder',
        data: {
          path: path,
          folder_name: newFolderName
        }
      }
    },
    // 压缩、解压
    zipFile (path, filename, type = 'unzip') {
      return {
        method: 'post',
        url: '/cloud/zipfile',
        data: {
          path: path,
          filename: filename,
          type: type
        }
      }
    },
    // 离线下载
    remoteDownload (url, path = './') {
      return {
        method: 'post',
        url: '/cloud/offline_download',
        data: {
          url: url,
          path: path
        }
      }
    },
    // 游客上传文件
    guestUpload (fileList, progressCallBack) {
      const formData = new FormData()
      formData.append('file', fileList[0])
      return {
        method: 'post',
        url: '/cloud/guest',
        headers: {
          'Content-Type': 'multipart/form-data;'
        },
        data: formData,
        // 进度回调函数
        onUploadProgress: progressCallBack
      }
    },
    // 下载分享文件
    downloadShare (shareCode) {
      return `${apiConfig.server}/cloud/download_share?share_code=${shareCode}`
    },
    // 删除文件
    delFile (path, filename) {
      return {
        method: 'POST',
        url: '/cloud/del',
        data: {
          path: `${path}`,
          filename: filename
        }
      }
    }
  },
  // 管理员
  admin: {
    // 管理员登录
    login (user, passwd) {
      return {
        method: 'post',
        url: '/admin/admin_login',
        data: {
          username: user,
          password: passwd
        }
      }
    },
    // 管理员登录测试
    loginTest () {
      return {
        method: 'post',
        url: '/admin/admin_test'
      }
    },
    // 获取用户存储信息
    getInfo (method) {
      return {
        method: method,
        url: '/admin/getInfo'
      }
    },
    // ddns模块
    ddns: {
      // 获取ddns状态、开关ddns服务
      getInfo (trigger = 'state') {
        return {
          method: 'get',
          url: '/admin/aliddns',
          params: {
            trigger: trigger
          }
        }
      },
      // 设置ddns配置
      setConf (key, sec, domainName, rrList) {
        return {
          method: 'post',
          url: '/admin/aliddns',
          data: {
            accessKeyId: key,
            accessSecret: sec,
            domain_name: domainName,
            rr_list: rrList
          }
        }
      }
    },
    // 删除文件
    delFile (path, filename) {
      return {
        method: 'POST',
        url: '/cloud/del',
        data: {
          path: `.${path}`,
          filename: filename
        }
      }
    },
    getLog (page, perPage = 20) {
      return {
        method: 'get',
        url: `/admin/getLog?page=${page}&per_page=${perPage}`
      }
    }
  },
  // 游客接口
  guest: {
    uploadFile (fileList, progressCallBack) {
      const formData = new FormData()
      formData.append('file', fileList[0])
      // formData.append('path', path)
      return {
        method: 'post',
        url: '/cloud/guest',
        headers: {
          'Content-Type': 'multipart/form-data;'
        },
        data: formData,
        // 进度回调函数
        onUploadProgress: progressCallBack
      }
    },
    downloadShare (shareCode) {
      return `${apiConfig.server}/cloud/download_share?share_code=${shareCode}`
    }
  }
}

module.exports = apiConfig
